package advance.x000.acw_138;


import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * https://www.acwing.com/problem/content/description/138/
 * 给定一个长度为 n 的序列 A，A 中的数各不相同。
 * <p>
 * 对于 A 中的每一个数 Ai，求：
 * <p>
 * min1≤j<i|Ai−Aj|
 * 以及令上式取到最小值的 j（记为 Pi）。若最小值点不唯一，则选择使 Aj 较小的那个。
 */
public class Main {

    public static class Node {
        int val;
        int idx;
        Node next;
        Node pre;
    }

    public static Node addNode(Node p, int val) {
        Node q = new Node();
        q.val = val;
        q.pre = p;
        q.next = p.next;
        p.next.pre = q;
        p.next = q;
        return q;
    }

    public static void deleteNode(Node p) {
        p.pre.next = p.next;
        p.next.pre = p.pre;
    }

    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);

        int n = read.nextInt();
        if (n <= 1) return;

        int[] arr = new int[n];
        int[] sort = new int[n];
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            sort[i] = arr[i] = read.nextInt();
            max = Math.max(arr[i], max);
        }
        Arrays.sort(sort);

        Node head = new Node();
        head.val = Integer.MAX_VALUE;
        head.idx = -1;
        Node tail = new Node();
        tail.val = Integer.MIN_VALUE;
        tail.idx = -1;
        head.next = tail;
        tail.pre = head;

        Node tmp = head;

        Map<Integer, Node> pos = new HashMap<>();
        for (int i = 0; i < n; i++) {
            pos.put(sort[i], addNode(tmp, sort[i]));
            tmp = tmp.next;
        }


        for (int i = 0; i < n; i++) {
            pos.get(arr[i]).idx = i;
        }

        int[] ans = new int[n + 1];

        for (int i = n - 1; i > 0; i--) {
            Node cur = pos.get(arr[i]);
            // 用while 查找会超时

            Node pre = cur.pre;
            Node next = cur.next;
            // 至多一个边界
            if (pre.idx == -1) {
                ans[i] = next.idx;
            } else if (next.idx == -1) {
                ans[i] = pre.idx;
            } else {
                ans[i] = Math.abs(cur.val - pre.val) <= Math.abs(cur.val - next.val) ? pre.idx : next.idx;
            }
            deleteNode(cur);

        }

        // 打印答案
        for (int i = 1; i < n; i++) {
            System.out.println(Math.abs(arr[i] - arr[ans[i]]) + " " + (ans[i] + 1));
        }

    }


}
